﻿using System;
using System.Web;
using System.IO;
using VioletDevelopmentLaboratory.Net.Web;

namespace VioletDevelopmentLaboratory.Net.Web.Component
{
	public abstract class BoardCategoryIconViewerHandlerBase : HandlerBase
	{
		public override void ProcessRequest(HttpContext context)
		{
			if (context == null)
			{
				throw new ArgumentNullException("context");
			}

			String categoryID = BoardParameters.CategoryID;

			if (!String.IsNullOrEmpty(categoryID) && VUtility.IsGuid(categoryID))
			{
				Byte[] image;
				String fileType;

				image = BoardCategory.GetIcon(BoardParameters.ComponentID, categoryID, out fileType);

				if (image != null)
				{
					context.Response.ContentType = fileType;
					context.Response.BinaryWrite(image);
					return;
				}
			}

			context.Response.ContentType = "image/gif";
			context.Response.TransmitFile(context.Server.MapPath(VUtility.GetVWebGlobalResource("IMG_NoIcon")));
		}
	}
}